package org.dromara.crawler.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.crawler.domain.SiteManager;
import org.dromara.crawler.mapper.SiteManagerMapper;
import org.dromara.crawler.service.SiteManagerService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SiteManagerServiceImpl extends ServiceImpl<SiteManagerMapper, SiteManager> implements SiteManagerService {


    @Override
    public SiteManager findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public IPage<SiteManager> queryByPage(SiteManager siteManager, PageQuery pageQuery) {
        LambdaQueryWrapper<SiteManager> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(siteManager.getSiteName()), SiteManager::getSiteName, siteManager.getSiteName());
        wrapper.eq(ObjectUtil.isNotEmpty(siteManager.getStatus()), SiteManager::getStatus, siteManager.getStatus());
        wrapper.orderByDesc(SiteManager::getCreateTime);
        return baseMapper.queryByPage(pageQuery.build(),wrapper);
    }

}
